import request from './request';

// 采购模块
const getPurchaseOrders = (params) => request({ url: '/purchase/orders/', method: 'GET', params });
const postPurchaseOrders = (data) => request({ url: '/purchase/orders/', method: 'POST', data });

// 库存模块
const getWarehouseInventory = (params) => request({ url: '/warehouse/inventory/', method: 'GET', params });
const putWarehouseInventory = (data) => request({ url: '/warehouse/inventory/', method: 'PUT', data });
const postWarehouseTransfers = (data) => request({ url: '/warehouse/transfers/', method: 'POST', data });

// 销售模块
const getSalesProducts = (params) => request({ url: '/sales/products/', method: 'GET', params });
const putSalesProductPrice = (id, data) => request({ url: `/sales/products/${id}/price/`, method: 'PUT', data });

// 配送模块
const postDeliveryOrders = (data) => request({ url: '/delivery/orders/', method: 'POST', data });

// 溯源模块
const getTraceProduct = (id) => request({ url: `/trace/products/${id}/`, method: 'GET' });

// 用户相关
const postLogin = (data) => request({ url: 'http://localhost:8000/api/auth/login', method: 'POST', data });
const postLogout = (data) => request({ url: 'http://localhost:8000/api/auth/logout', method: 'POST', data });

// 产品相关
const getProducts = (params) => request({ url: 'http://localhost:8000/api/products', method: 'GET', params });
const getProductDetail = (id) => request({ url: `http://localhost:8000/api/products/${id}`, method: 'GET' });

// 仓库相关
const getWarehouses = (params) => request({ url: 'http://localhost:8000/api/warehouses', method: 'GET', params });
const getWarehouseDetail = (id) => request({ url: `http://localhost:8000/api/warehouses/${id}`, method: 'GET' });
const getInventory = (params) => request({ url: 'http://localhost:8000/api/inventory', method: 'GET', params });
const postInventoryAdjust = (data) => request({ url: 'http://localhost:8000/api/inventory/adjust', method: 'POST', data });

// 订单相关
const getOrders = (params) => request({ url: 'http://localhost:8000/api/orders', method: 'GET', params });
const getOrderDetail = (id) => request({ url: `http://localhost:8000/api/orders/${id}`, method: 'GET' });
const postOrderCancel = (id) => request({ url: `http://localhost:8000/api/orders/${id}/cancel`, method: 'POST' });

// 配送相关
const getDeliveries = (params) => request({ url: 'http://localhost:8000/api/deliveries', method: 'GET', params });
const getDeliveryDetail = (id) => request({ url: `http://localhost:8000/api/deliveries/${id}`, method: 'GET' });
const postDeliveryAssign = (id, data) => request({ url: `http://localhost:8000/api/deliveries/${id}/assign`, method: 'POST', data });
const postDeliveryStatus = (id, data) => request({ url: `http://localhost:8000/api/deliveries/${id}/status`, method: 'POST', data });

// 销售管理模块 - 订单视图集
const getFilteredOrders = (params) => request({ url: `http://localhost:8000/api/orders/?status=${params.status}&customer=${params.customer_id}`, method: 'GET' });
const postCreateOrder = (data) => request({ url: 'http://localhost:8000/api/orders/', method: 'POST', data });
const postPayOrder = (id, data) => request({ url: `http://localhost:8000/api/orders/${id}/pay/`, method: 'POST', data });

const api = {
  getPurchaseOrders,
  postPurchaseOrders,
  getWarehouseInventory,
  putWarehouseInventory,
  postWarehouseTransfers,
  getSalesProducts,
  putSalesProductPrice,
  postDeliveryOrders,
  getTraceProduct,
};

export default api;